package pro.seac.twitter.application.dao;

import java.io.Serializable;

import org.hibernate.Session;
import org.hibernate.SessionFactory;

public abstract class BaseDao<T, ID extends Serializable> {
	private SessionFactory sessionFactory;
	private Class<T> clazz;

	protected BaseDao(SessionFactory sessionFactory, Class<T> clazz) {
		this.sessionFactory = sessionFactory;
		this.clazz = clazz;
	}

	protected Session getSession() {
		return sessionFactory.getCurrentSession();
	}

	@SuppressWarnings("unchecked")
	public T findOne(ID id) {
		return (T) getSession().get(clazz, id);
	}

	public void save(T entity) {
		getSession().saveOrUpdate(entity);
	}

}
